<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2020年6月3日</title>
</head>
<style>
    .tip {
        font-size: 12px;
        color: gray;
    }

    #showAnswerBtn {
        display: inline-block;
        background-color: darkgreen;
        color: #fff;
        padding: 10px;
        border-radius: 5px;
    }

    #answer {
        display: none;
    }
</style>

<body>
    关于下面的一段代码，以下哪些说法是正确的：（多选）<br>
    <div>
        public static void main(String[] args) {
        <br>
        String a = new String("myString");
        <br>
        String b = "myString";
        <br>
        String c = "my" + "String";
        <br>
        String d = c;
        <br>
        System.out.print(a == b);
        <br>
        System.out.print(a == c);
        <br>
        System.out.print(b == c);
        <br>
        System.out.print(b == d);
        }
    </div>
    <br>
    A. System.out.print(a == b)打印出来的是false
    <br>
    B. System.out.print(a == c)打印出来的是true
    <br>
    C. System.out.print(b == c)打印出来的是false
    <br>
    D. System.out.print(b == d)打印出来的是true

    <div>
        <span id="showAnswerBtn">点击查看正确答案</span>
    </div>
    <div id="answer">
        <p>答案：AD</p>
        <p>
            A：a指向堆内存，b指向常量池，因此地址不相等，false
            <br>
            B：java有常量优化机制，c也指向常量池，且与b指向同一个，则a与c地址不相等,false；
            <br>
            C：b与c地址相等，true
            <br>
            D：d是c的副本，地址相同，所以b与d地址相等，true

        </p>
    </div>
    <p class="tip">
        来源：<a href=""></a>
    </p>
    <script>
        document.getElementById("showAnswerBtn").onclick = function () {
            document.getElementById("answer").style.display = "block";
            document.getElementById("showAnswerBtn").style.display = "none";
        }
    </script>
</body>

</html>